package cn.enilu.flash.mobile.controller;

import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.entity.bus.Enterprise;
import cn.enilu.flash.bean.entity.bus.Repair;
import cn.enilu.flash.bean.enumeration.bus.RepairType;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.mobile.domain.EnterpriseDomain;
import cn.enilu.flash.mobile.domain.RepairDomain;
import cn.enilu.flash.service.bus.CollectionService;
import cn.enilu.flash.service.bus.EnterpriseService;
import cn.enilu.flash.service.bus.RepairService;
import cn.enilu.flash.utils.factory.Page;
import cn.enilu.flash.web.controller.BaseController;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;


@RestController
@RequestMapping("/repair")
public class RepairController extends BaseController {

    @Autowired
    private RepairService repairService;

    @GetMapping(value = "/list")
    public Object list() {
        Long idUser = getIdUser();
        Page<Repair> page = new PageFactory<Repair>().defaultPage();
        page.addFilter(SearchFilter.build("userId", idUser));
        page = repairService.queryPage(page);
        return Rets.success(page);
    }

    @PostMapping(value = "/add")
    public Object getInfoById(@RequestBody RepairDomain repairDomain) {
        Repair repair = new Repair();
        BeanUtils.copyProperties(repairDomain, repair);
        Long idUser = getIdUser();
        repair.setCreateBy(idUser);
        repair.setUserId(idUser);
        repair.setState(RepairType.WAIT.getCol());
        Repair insert = repairService.insert(repair);
        return Rets.success(insert);
    }

}
